/** * DevToolKit - English Version * Entry point - all requests routed through this file * Auto-detects domain name for SEO */ // Get current domain for canonical URLs $domain = $_SERVER['HTTP_HOST'] ?? 'toolsinbox.top'; $scheme = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') ? 'https' : 'http'; $baseUrl = $scheme . '://' . $domain; // Define root path define('ROOT_PATH', __DIR__ . '/'); define('VIEWS_PATH', ROOT_PATH . 'views/'); define('BASE_URL', $baseUrl); // Load configuration $config = include ROOT_PATH . 'config.php'; // Get requested path $requestUri = $_SERVER['REQUEST_URI'] ?? '/'; $scriptName = $_SERVER['SCRIPT_NAME'] ?? ''; // Remove query string $requestUri = strtok($requestUri, '?'); // Remove script name prefix if present (for non-rewrite access) if ($scriptName && strpos($requestUri, $scriptName) === 0) { $requestUri = substr($requestUri, strlen($scriptName)); } // Remove trailing slash (except for root) if ($requestUri !== '/' && substr($requestUri, -1) === '/') { $requestUri = rtrim($requestUri, '/'); } // Default to homepage if empty if (empty($requestUri) || $requestUri === '/') { $page = 'index'; $tool = null; } else { // Parse route: /tool-name or /tool-name/ // Also handle /index.php/tool-name style $path = trim($requestUri, '/'); // Map common routes $routeMap = [ '' => 'index', 'index' => 'index', 'json-formatter' => 'json-formatter', 'json-minifier' => 'json-minifier', 'json-validator' => 'json-validator', 'json-to-java' => 'json-to-java', 'json-to-csharp' => 'json-to-csharp', 'json-to-go' => 'json-to-go', 'json-to-python' => 'json-to-python', 'json-to-typescript' => 'json-to-typescript', 'json-to-xml' => 'json-to-xml', 'json-to-yaml' => 'json-to-yaml', 'json-to-csv' => 'json-to-csv', 'html-formatter' => 'html-formatter', 'html-minifier' => 'html-minifier', 'css-formatter' => 'css-formatter', 'css-minifier' => 'css-minifier', 'js-formatter' => 'js-formatter', 'js-minifier' => 'js-minifier', 'sql-formatter' => 'sql-formatter', 'xml-formatter' => 'xml-formatter', 'regex-tester' => 'regex-tester', 'base64' => 'base64', 'url-encode' => 'url-encode', 'md5-hash' => 'md5-hash', 'sha256-hash' => 'sha256-hash', 'sha512-hash' => 'sha512-hash', 'password-generator' => 'password-generator', 'uuid-generator' => 'uuid-generator', 'color-converter' => 'color-converter', 'unicode-converter' => 'unicode-converter', 'word-counter' => 'word-counter', 'case-converter' => 'case-converter', 'timestamp-converter' => 'timestamp-converter', 'ip-lookup' => 'ip-lookup', 'whois-lookup' => 'whois-lookup', 'dns-lookup' => 'dns-lookup', 'http-headers' => 'http-headers', 'http-status-codes' => 'http-status-codes', 'scientific-calculator' => 'scientific-calculator', 'percentage-calculator' => 'percentage-calculator', 'loan-calculator' => 'loan-calculator', 'bmi-calculator' => 'bmi-calculator', 'length-converter' => 'length-converter', 'weight-converter' => 'weight-converter', 'temperature-converter' => 'temperature-converter', 'qr-code-generator' => 'qr-code-generator', 'barcode-generator' => 'barcode-generator', 'image-to-base64' => 'image-to-base64', 'favicon-generator' => 'favicon-generator', 'hash-generator' => 'hash-generator', 'morse-code' => 'morse-code', 'jwt-decoder' => 'jwt-decoder', 'curl-generator' => 'curl-generator', 'diff-checker' => 'diff-checker', 'lorem-ipsum' => 'lorem-ipsum', 'slug-generator' => 'slug-generator', 'text-replacer' => 'text-replacer', 'ascii-table' => 'ascii-table', 'sitemap.xml' => 'sitemap', 'robots.txt' => 'robots', ]; if (isset($routeMap[$path])) { $page = $routeMap[$path]; } else { $page = $path; } } // Load the page $viewFile = VIEWS_PATH . $page . '.php'; if ($page === 'sitemap') { header('Content-Type: application/xml; charset=utf-8'); echo generateSitemap($config, $baseUrl); exit; } if ($page === 'robots') { header('Content-Type: text/plain; charset=utf-8'); echo generateRobots($baseUrl); exit; } if ($page === '404') { http_response_code(404); $viewFile = VIEWS_PATH . '404.php'; } if (!file_exists($viewFile)) { http_response_code(404); $viewFile = VIEWS_PATH . '404.php'; } // Extract SEO config for current page $seo = $config['seo'][$page] ?? $config['seo']['index']; $seo['canonical'] = $baseUrl . '/' . ($page === 'index' ? '' : $page); $seo['current_url'] = $baseUrl . '/' . ($page === 'index' ? '' : $page); // Include header include VIEWS_PATH . 'header.php'; // Include page content include $viewFile; // Include footer include VIEWS_PATH . 'footer.php'; function generateSitemap($config, $baseUrl) { $urls = []; foreach ($config['seo'] as $key => $data) { $loc = $baseUrl . '/' . ($key === 'index' ? '' : $key); $urls[] = ' ' . htmlspecialchars($loc) . ' ' . ($key === 'index' ? 'daily' : 'weekly') . ' ' . ($key === 'index' ? '1.0' : '0.8') . ' '; } return '<' . '?xml version="1.0" encoding="UTF-8"?> ' . implode("\n", $urls) . ' '; } function generateRobots($baseUrl) { return "User-agent: * Allow: / Disallow: /api/ Sitemap: {$baseUrl}/sitemap.xml "; }